<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/5/1
  Time: 22:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
</head>
<body>
<table border="1">

    <tr>

        <td width="200" align="center">文件上传${msg}</td>

        <td width="300" align="center">下载列表</td>

    </tr>

    <tr>

        <td height="100">

            <form action="${pageContext.request.contextPath}/fileUpLoad"

                  method="post" enctype="multipart/form-data">

                <input type="file" name="files" multiple="multiple"><br/>

                <input type="reset" value="清空" />

                <input type="submit" value="提交"/>

            </form>

        </td>

        <td id="files"></td>

    </tr>

</table>
<script>
    $(document).ready(function(){
        var url = "${pageContext.request.contextPath}/getFilesName";
        $.ajax({
            url:url,
            type:"GET",
            success:function (data){
                console.log(data);
                var files = eval('(' + data + ')');

                for (var i=0;i<files.length;i++){

                    $("#files").append("<li > <a href=${pageContext.request.contextPath }"+"\\"+"download?filename="+files[i].name+">"+ files[i].name+"</a></li>" );
                }
                }
            })
    })

</script>
</body>
</html>
